import {
  getBusiness
} from '../../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getBusinessData:{
      p:1,
      id:""
    },
    gonglv: {
      id: "",
      attack_id: "",
      p: ""
    },
    nickName:"",
    avatarUrl:"",
    busyList: [],
    isdata: true,
    headImg:"",
    shopName: ""
  },     

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var aImg=JSON.parse(options.headImg)
    var shop_name = JSON.parse(options.shop_name)
    let getBusinessDataID ="getBusinessData.id"
    that.setData({
      [getBusinessDataID]: options.businessDetails,
      headImg: aImg,
      shopName: shop_name
    })
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollHeight: res.windowHeight * 2
        });
      }
    });
    wx.getUserInfo({
      success: function (res) {
        that.setData({
          nickName: res.userInfo.nickName
        })
      }
    })
    that.getBusy()
  },
  getBusy(){
    getBusiness(this.data.getBusinessData).then(res => {
      if (res.code == 200) {
        this.setData({
          busyList: this.data.busyList.concat(res.datas.list)
        })
        if (res.datas.more == false) {
          this.setData({
            isdata: false
          })
        }
      } else {
        this.setData({
          busyList: []
        })
      }
    })
  },
  //滚动事件bindDownLoad
  bindDownLoad(e) {
    if (this.data.isdata) {
      this.data.getBusinessData.p++
      this.getBusy()
    } else {
      wx.showToast({
        title: '到底了',
        icon: 'none'
      })
    }
  },
  //图片放大
  previewIamge2(event) {
    const nowIndex = event.currentTarget.dataset.id;
    const imgList = event.currentTarget.dataset.list
    wx.previewImage({
      current: imgList[nowIndex], //当前预览的图片
      urls: imgList, //所有要预览的图片
    })
  },
  //选择地点
  searchTravel(e){
    let id = 'gonglv.id';
    let attack_id = 'gonglv.attack_id'
    this.setData({
      [id]: e.currentTarget.dataset.id.id,
      [attack_id]: e.currentTarget.dataset.id.attack_id
    })
    //let gonglv = JSON.stringify(this.data.gonglv)
    let gonglv = JSON.stringify(this.data.gonglv)
    wx.navigateTo({
      url: '../../strategy/details/details?data=' + gonglv,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})